import { getConfig } from '@/config/api';

const config = getConfig();

export const dark = {
  version: 8,
  sprite: `${config.mapboxAssets}/style/sprite`,
  glyphs: `${config.mapboxAssets}/glyphs/mapbox/{fontstack}/{range}.pbf`,
  sources: {
    // 为每个图层创建独立的数据源
    osm_lines: {
      type: 'vector',
      tiles: [
        `${config.geoServer}/gwc/service/tms/1.0.0/test:planet_osm_line@EPSG:3857@pbf/{z}/{x}/{y}.pbf`
      ]
    },
    osm_polygons: {
      type: 'vector',
      tiles: [
        `${config.geoServer}/gwc/service/tms/1.0.0/test:planet_osm_polygon@EPSG:3857@pbf/{z}/{x}/{y}.pbf`
      ]
    },
    osm_points: {
      type: 'vector',
      tiles: [
        `${config.geoServer}/gwc/service/tms/1.0.0/test:planet_osm_point@EPSG:3857@pbf/{z}/{x}/{y}.pbf`
      ]
    }
  },
  layers: [
    // 背景
    {
      id: 'background',
      type: 'background',
      paint: { 'background-color': 'hsl(0, 0%, 16%)' }
    },

    // 水域（从多边形中过滤）
    {
      id: 'water',
      type: 'fill',
      source: 'osm_polygons',
      'source-layer': 'planet_osm_polygon',
      filter: [
        'any',
        ['==', 'waterway', 'riverbank'],
        ['==', 'natural', 'water']
      ],
      paint: { 'fill-color': 'hsl(0, 0%, 12%)' }
    },

    // 道路（从线图层中过滤）
    {
      id: 'roads_major',
      type: 'line',
      source: 'osm_lines',
      'source-layer': 'planet_osm_line',
      filter: ['in', 'highway', 'motorway', 'trunk', 'primary'],
      paint: {
        'line-color': '#555555',
        'line-width': {
          base: 1.2,
          stops: [
            [10, 1],
            [18, 8]
          ]
        }
      }
    },

    // 建筑（从多边形中过滤）
    {
      id: 'buildings',
      type: 'fill',
      source: 'osm_polygons',
      'source-layer': 'planet_osm_polygon',
      filter: ['==', 'building', 'yes'],
      paint: {
        'fill-color': 'hsl(0, 0%, 20%)',
        'fill-opacity': 0.6
      }
    },

    // POI（从点图层中过滤）
    {
      id: 'poi_labels',
      type: 'symbol',
      source: 'osm_points',
      'source-layer': 'planet_osm_point',
      filter: ['has', 'name'],
      layout: {
        'text-field': ['coalesce', ['get', 'name:zh'], ['get', 'name']],
        'text-size': 10,
        'text-allow-overlap': false
      },
      paint: {
        'text-color': 'hsl(0, 0%, 70%)',
        'text-halo-color': 'hsl(0, 0%, 10%)',
        'text-halo-width': 1
      }
    }
  ]
};
